package com.sptpc.demo.controller;

import com.sptpc.demo.controller.requests.ModifyDrinkRquest;
import com.sptpc.demo.model.Drink;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
@Slf4j
@RestController 
@RequestMapping("/drink")

public class DrinkController {
    //get /drink
    //@RequestMapping(value = "/",method = RequestMethod.GET)
    @GetMapping("/")
    public List<Drink> getAll() {
        //后期从数据库查询

        ArrayList<Drink> result = new ArrayList<>();
        Drink drink1 = Drink.builder().id(1L).name("刘德华")
                .adminssionDate("2019-9-01")
                .major("软件技术").build();
        result.add(drink1);
        Drink drink3 = Drink.builder().id(2L).name("郭富城")
                .adminssionDate("2019-09-01")
                .major("唱跳").build();
        result.add(drink3);
        Drink drink4 = Drink.builder().id(3L).name("王杰")
                .adminssionDate("2019-09-01")
                .major("谁明浪子心").build();
        result.add(drink4);

        return result;
    }

    //查询
    //get/drink/1
    //get/drink/?id=1
    @GetMapping("/{id}")
    public Drink getDrink(@PathVariable Integer id) {
        log.info("查询：{}", id);
        Drink drink=Drink.builder().id(3L).name("王杰")
                .adminssionDate("2019-09-01")
                .major("软件技术").build();
        return drink;

    }

    //传参思路
    //直接用实体类
    @PostMapping("/")
    public Drink addNewDrink(@RequestBody Drink drink) {
        log.info("新增学生类:{}", drink);
        //后期inster数据库
        Drink drink2 = Drink.builder().id(7L).name("你的名字")
                .adminssionDate("2019-09-01")
                .major("软件技术").build();
        return drink2;
    }

    //修改
    @PutMapping("/")
    public Drink modifyDrink(@RequestBody ModifyDrinkRquest request) {
        log.info("修改饮品: {}", request);
        //后期update数据库
        Drink drink3 =Drink.builder().id(7L).name("你的名字")
                .adminssionDate("2019-09-01")
                .major("软件技术").build(); ;
        return drink3;
    }
    @DeleteMapping("/{id}")
    public String deleteDrink(@PathVariable Integer id){
        log.info("删除饮品: {}",id);
        return "删除成功";

    }

}